//
//  SISSImportantSellerFillInView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/9/6.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSImportantSellerFillInView.h"

@interface SISSImportantSellerFillInView ()

/// topTitleLabel
@property (weak, nonatomic) UILabel *topTitleLabel;
/// bgView
@property (weak, nonatomic) UIView *bgView;
/// firstTitleLabel
@property (weak, nonatomic) UILabel *firstTitleLabel;
/// firstOneButton
@property (weak, nonatomic) UIButton *firstOneButton;
/// firstTwoButton
@property (weak, nonatomic) UIButton *firstTwoButton;
/// firstTwoLabel
@property (weak, nonatomic) UILabel *firstTwoLabel;

/// secondTitleLabel
@property (weak, nonatomic) UILabel *secondTitleLabel;
/// secondOneButton
@property (weak, nonatomic) UIButton *secondOneButton;
/// secondTwoButton
@property (weak, nonatomic) UIButton *secondTwoButton;
/// textField
@property (weak, nonatomic) UITextField *textField;
/// secondTwoLabel
@property (weak, nonatomic) UILabel *secondTwoLabel;
/// secondThreeLabel
@property (weak, nonatomic) UILabel *secondThreeLabel;

@end
@implementation SISSImportantSellerFillInView


- (void)setLeaseState:(NSInteger)leaseState {
    _leaseState = leaseState; // 1未出租 2已出租
    
    self.topTitleLabel.hidden = leaseState;
    switch (leaseState) {
        case 0: {
            self.firstOneButton.selected = NO;
            self.firstTwoButton.selected = NO;
        }
            break;
            
        case 1: {
            self.firstOneButton.selected = YES;
            self.firstTwoButton.selected = NO;
        }
            break;
            
        case 2: {
            self.firstOneButton.selected = NO;
            self.firstTwoButton.selected = YES;
        }
            break;
            
        default:
            break;
    }
}

- (void)setPropertyState:(NSInteger)propertyState {
    _propertyState = propertyState; // 1 存在共有  2 不存在共有
    
    self.topTitleLabel.hidden = propertyState;
    switch (propertyState) {
        case 0: {
            self.secondOneButton.selected = NO;
            self.secondTwoButton.selected = NO;
        }
            break;
            
        case 1: {
            self.secondOneButton.selected = NO;
            self.secondTwoButton.selected = YES;
        }
            break;
            
        case 2: {
            self.secondOneButton.selected = YES;
            self.secondTwoButton.selected = NO;
        }
            break;
            
        default:
            break;
    }
}

- (void)setCoownerName:(NSString *)coownerName {
    _coownerName = coownerName;
    self.textField.text = coownerName;
}


#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *topTitleLabel = [[UILabel alloc] init];
    topTitleLabel.text = @"待卖方填写";
    topTitleLabel.textColor = MAIN_TEXT_COLOR;
    topTitleLabel.textAlignment = NSTextAlignmentCenter;
    topTitleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:topTitleLabel];
    self.topTitleLabel = topTitleLabel;
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = COLOR(0xF1F1F5);
    bgView.layer.cornerRadius = 5;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    self.bgView = bgView;
    
    UILabel *firstTitleLabel = [[UILabel alloc] init];
    firstTitleLabel.text = @"四、卖方出售的房屋：";
    firstTitleLabel.textColor = MAIN_TEXT_COLOR;
    firstTitleLabel.numberOfLines = 0;
    firstTitleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.bgView addSubview:firstTitleLabel];
    self.firstTitleLabel = firstTitleLabel;
    
    UIButton *firstOneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [firstOneButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [firstOneButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [firstOneButton setTitleColor:SECONDARY_TEXT_COLOR forState:UIControlStateNormal];
    [firstOneButton setTitle:@"无租约" forState:UIControlStateNormal];
    firstOneButton.userInteractionEnabled = NO;
    [self.bgView addSubview:firstOneButton];
    self.firstOneButton = firstOneButton;
    
    UIButton *firstTwoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [firstTwoButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [firstTwoButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    firstTwoButton.userInteractionEnabled = NO;
    [self.bgView addSubview:firstTwoButton];
    self.firstTwoButton = firstTwoButton;
    
    UILabel *firstTwoLabel = [[UILabel alloc] init];
    firstTwoLabel.text = @"有租约，并已获得了承租人明示或者默示放弃优先购买权的声明。";
    firstTwoLabel.textColor = SECONDARY_TEXT_COLOR;
    firstTwoLabel.numberOfLines = 0;
    firstTwoLabel.font = [UIFont systemFontOfSize:16];
    [self.bgView addSubview:firstTwoLabel];
    self.firstTwoLabel = firstTwoLabel;
    
    UILabel *secondTitleLabel = [[UILabel alloc] init];
    secondTitleLabel.text = @"五、卖方房产：";
    secondTitleLabel.textColor = MAIN_TEXT_COLOR;
    secondTitleLabel.numberOfLines = 0;
    secondTitleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.bgView addSubview:secondTitleLabel];
    self.secondTitleLabel = secondTitleLabel;
    
    UIButton *secondOneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [secondOneButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [secondOneButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [secondOneButton setTitleColor:SECONDARY_TEXT_COLOR forState:UIControlStateNormal];
    [secondOneButton setTitle:@"无共有权人" forState:UIControlStateNormal];
    firstOneButton.userInteractionEnabled = NO;
    [self.bgView addSubview:secondOneButton];
    self.secondOneButton = secondOneButton;
    
    UIButton *secondTwoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [secondTwoButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [secondTwoButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [secondTwoButton sizeToFit];
    [secondTwoButton setTitleColor:SECONDARY_TEXT_COLOR forState:UIControlStateNormal];
    [secondTwoButton setTitle:@"有共有权人：" forState:UIControlStateNormal];
    secondTwoButton.userInteractionEnabled = NO;
    [self.bgView addSubview:secondTwoButton];
    self.secondTwoButton = secondTwoButton;
    
    UITextField *textField = [[UITextField alloc] init];
//    textField.placeholder = @"请输入有共有权人姓名。";
    textField.userInteractionEnabled = NO;
//    textField.borderStyle = UITextBorderStyleLine;
    [self.bgView addSubview:textField];
    self.textField = textField;
    
    UILabel *secondTwoLabel = [[UILabel alloc] init];
    secondTwoLabel.text = @"";
    secondTwoLabel.textColor = SECONDARY_TEXT_COLOR;
    secondTwoLabel.numberOfLines = 0;
    secondTwoLabel.font = [UIFont systemFontOfSize:16];
    [self.bgView addSubview:secondTwoLabel];
    self.secondTwoLabel = secondTwoLabel;
    
    UILabel *secondThreeLabel = [[UILabel alloc] init];
    secondThreeLabel.text = @"已征得共有权人同意。\n【注：按我国《婚姻法》的规定，夫妻双方婚姻关系存续期间所得的房屋，归夫妻双方共同所有，除非夫妻双方有特别约定。如属此类产权证上未注明的情况请如实填写。】";
    secondThreeLabel.textColor = SECONDARY_TEXT_COLOR;
    secondThreeLabel.numberOfLines = 0;
    secondThreeLabel.font = [UIFont systemFontOfSize:16];
    [self.bgView addSubview:secondThreeLabel];
    self.secondThreeLabel = secondThreeLabel;
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    WeakSelf
    [self.topTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf);
        make.top.equalTo(weakSelf).offset(margin);
    }];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(margin);
        make.top.equalTo(weakSelf.topTitleLabel.mas_bottom).offset(margin);
        make.right.equalTo(weakSelf).offset(-2 * margin);
        make.bottom.equalTo(weakSelf).offset(-margin);
    }];
    
    [self.firstTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(weakSelf.bgView).offset(margin);
        make.right.equalTo(weakSelf.bgView).offset(-margin);
    }];
    
    [self.firstOneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstTitleLabel);
        make.top.equalTo(weakSelf.firstTitleLabel.mas_bottom).offset(2 * margin);
    }];
    [self.firstTwoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstOneButton);
        make.top.equalTo(weakSelf.firstOneButton.mas_bottom).offset(2 * margin);
        make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
    
    [self.firstTwoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstTwoButton.mas_right);
        make.top.equalTo(weakSelf.firstTwoButton);
        make.right.equalTo(weakSelf.bgView).offset(-margin);
    }];
    
    [self.secondTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstTitleLabel);
        make.top.equalTo(weakSelf.firstTwoLabel.mas_bottom).offset(3 * margin);
         make.right.equalTo(weakSelf.bgView).offset(-margin);
    }];
    
    [self.secondOneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondTitleLabel);
        make.top.equalTo(weakSelf.secondTitleLabel.mas_bottom).offset(margin);
    }];
    [self.secondTwoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondOneButton);
        make.top.equalTo(weakSelf.secondOneButton.mas_bottom).offset(margin);
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondTwoButton.mas_right);
        make.centerY.equalTo(weakSelf.secondTwoButton);
    }];
    [self.secondTwoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.secondTwoButton);
        make.right.equalTo(weakSelf.bgView).offset(-margin);
    }];
    [self.secondThreeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondTitleLabel);
        make.right.equalTo(weakSelf.bgView).offset(-margin);
        make.top.equalTo(weakSelf.secondTwoButton.mas_bottom).offset(margin);
        make.bottom.equalTo(weakSelf.bgView).offset(-margin);
    }];
}

@end
